package com.aidysoft.practice.easypoi.pdf;

import cn.afterturn.easypoi.pdf.entity.PdfExportParams;
import com.aidysoft.practice.easypoi.demo1.entity.StudentEntity;
import com.aidysoft.practice.easypoi.demo1.excelData.ExcelData;
import com.aidysoft.practice.easypoi.utils.style.PdfStyleUtil;
import com.aidysoft.practice.easypoi.utils.PdfExportUtil;
import com.itextpdf.text.Document;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class PdfExportController {

    @GetMapping("/exportPdf")
    public String exportPdf(HttpServletResponse response){
        ExcelData excelData = new ExcelData();
        PdfExportParams pdf = new PdfExportParams("特色tPdf","sss");
        pdf.setStyler(new PdfStyleUtil());
        try {
            Document document = PdfExportUtil.exportPdf
                    (
                    pdf,
                            StudentEntity.class,
                            excelData.getEasyList(),
                            response.getOutputStream()
                    );
            document.addKeywords("aidy");
            document.newPage();

            document.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  "ok";
    }
}
